# import pyautogui
import time

import win32api
import win32clipboard
import win32con

from base.utils.TimeUtil import TimeUtil


class Windows:
    '''
    键和键码对应表:
    https://blog.csdn.net/weixin_42129248/article/details/89738210
    '''

    # 安装pywin32包 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pywin32
    # 复制文本到粘贴板
    @staticmethod
    def copy_text(text: str):
        # 打开粘贴版
        win32clipboard.OpenClipboard()
        # 清空粘贴板
        win32clipboard.EmptyClipboard()
        # 设置复制的内容
        win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT, text)
        # 关闭粘贴板线程
        win32clipboard.CloseClipboard()

    # 实现模拟点击ctrl+v
    @staticmethod
    def paste_text():
        win32api.keybd_event(17, 0, 0, 0)  # ctrl
        win32api.keybd_event(86, 0, 0, 0)  # v
        win32api.keybd_event(86, 0, win32con.KEYEVENTF_KEYUP, 0)  # 释放按键
        win32api.keybd_event(17, 0, win32con.KEYEVENTF_KEYUP, 0)

    # 实现模拟点击ctrl+a
    @staticmethod
    def select_all():
        win32api.keybd_event(17, 0, 0, 0)  # ctrl
        win32api.keybd_event(65, 0, 0, 0)  # a
        win32api.keybd_event(65, 0, win32con.KEYEVENTF_KEYUP, 0)  # 释放按键
        win32api.keybd_event(17, 0, win32con.KEYEVENTF_KEYUP, 0)

    @staticmethod
    def enter():
        win32api.keybd_event(0x0D, 0, 0, 0)
        win32api.keybd_event(0x0D, 0, win32con.KEYEVENTF_KEYUP, 0)

    # 鼠标左键单击
    @staticmethod
    def click(x, y):
        win32api.SetCursorPos([x, y])
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
        TimeUtil.short_sleep()
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)

    # 安装pyautogui包 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyautogui
    # 获取当前鼠标位置
    # @staticmethod
    # def get_mouse_position():
    #     x, y = pyautogui.position()

    #     return x, y


if __name__ == '__main__':
    Windows.enter()
